﻿namespace ApiTemplate.WebApi
{
    /// <summary>
    /// 初始化数据库
    /// </summary>
    public class AppStart : IStartable
    {
        private readonly ICommonApplication commonApplication;

        private readonly ISchedulerApplication schedulerApplication;

        /// <summary>
        /// 构造注入
        /// </summary>
        /// <param name="commonApplication"></param>
        /// <param name="schedulerApplication"></param>
        public AppStart(ICommonApplication commonApplication, ISchedulerApplication schedulerApplication)
        {
            this.schedulerApplication = schedulerApplication;
            this.commonApplication = commonApplication;
        }

        /// <summary>
        /// 初始化数据库
        /// </summary>
        public void Start()
        {
            AppSetting appSetting = ConfigHelper.GetAppSetting();
            if (appSetting.InitDataTable)
            {
                commonApplication.InitDataTable();
            }
            if (appSetting.EnableSchedulerTask)
            {
                schedulerApplication.InitSchedulerTask();
            }
        }
    }
}
